package anroid.vstore.provider;

import java.util.ArrayList;

import DTO.ImageDTO;
import DTO.ProductDTO;
import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;

public class UpdateSttListThread {
	
	
	Thread _thread = null;
	ArrayList<ProductDTO> _list;
	public int _start;
	public int _end;
	Handler _messageHandler;
	Activity _activity;
	public UpdateSttListThread()
	{
		
	}
	public UpdateSttListThread(Activity activity, Handler handler, ArrayList<ProductDTO> list, int start, int end)
	{
		_list = list;
		_start = start;
		_end = end;
		_messageHandler = handler;
		_activity = activity;
	}
	public void LoadMore(int endindx)
	{
//		_start = _end;
		_end = endindx;
		Load();
	}
	public Boolean isAlive()
	{
		return _thread.isAlive();
	}
	public void Interrupt()
	{
		if(_thread != null && _thread.isAlive())
			_thread.interrupt();
	}
	public void Load()
    {
		if(_thread != null)
		{
			_thread.interrupt();
		}
		_thread = new Thread()
		{
			@Override
			public void run() {
				if(_list.size() > 0) {
	    			if(_end >= _list.size())
	    				_end = _list.size()-1;
	    			for(int i=_start ; i<=_end ; i++)
	    			{
	    				ProductDTO.VerifyAppStatus(_activity, _list.get(i));
//	    				_list.get(i).loadImage();
	    				_messageHandler.sendMessage(Message.obtain(_messageHandler, Constant.REFRESH_ALL_PAGE, 0, 0, null));
	    			}
//	    			_messageHandler.sendMessage(Message.obtain(_messageHandler, Constant.REFRESH_ALL_PAGE, 0, 0, null));
	    		}									
				
			}
		};
		_thread.start();	
    }
	
}
